
package com.bluelinelabs.conductor.demo.controllers;

import ohos.agp.components.Component;
import ohos.agp.components.TextField;

import com.bluelinelabs.conductor.conductor.Controller;
import com.bluelinelabs.conductor.demo.ResourceTable;
import com.bluelinelabs.conductor.demo.controllers.base.BaseController;

/**
 * lipeiquan
 *
 * @since 2021-05-06
 */
public class TargetTitleEntryController extends BaseController {
    private TextField id_edit_text;

    public TargetTitleEntryController() {
        super(ResourceTable.Layout_controller_target_title_entry);
    }

    public TargetTitleEntryController(TargetTitleEntryControllerListener targetController) {
        super(ResourceTable.Layout_controller_target_title_entry);
        if (targetController instanceof Controller) {
            setTargetController((Controller) targetController);
        }
    }

    @Override
    public void onViewCreated(ohos.agp.components.Component component) {
        id_edit_text = (TextField) component.findComponentById(ResourceTable.Id_edit_text);
        component.findComponentById(ResourceTable.Id_use_title_button).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (getTargetController() != null) {
                    if (getTargetController() instanceof TargetTitleEntryControllerListener) {
                        ((TargetTitleEntryControllerListener) getTargetController()).onTitlePicked(id_edit_text.getText());
                    }
                    getRouter().popController(TargetTitleEntryController.this);
                }
            }
        });
    }

    public interface TargetTitleEntryControllerListener {
        void onTitlePicked(String option);
    }
}
